<!--  货补池管理-->
<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <search ref='search' :config='searchConfig' @search='search' @getHeight='getHeight' />

    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        v-bind='vexConfig'
        :align='left'
        :border='true'
        :checkbox-config='checkboxConfig'
        :columns='columns'
        :data='dataSource'
        :height='pageHeight-seachHeight-94'
        :loading='loading'
        :resizable='true'
        :showOverflow='true'
        :toolbar-config='tableToolbar'
        size='mini'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >
        <template #toolbar_buttons>
            <!-- 操作按钮区域 -->
            <div class='table-operator'>
              <a-button type="primary" @click="handleAdd">新增</a-button>
              <a-button type='primary' @click='batchDel'>删除</a-button>
              <a-button type="primary" @click="stateChange(1)">启用</a-button>
              <a-button type="primary" @click="stateChange(0)">禁用</a-button>
              <a-button type="primary" @click="handleExportXls('货补池管理')">模板下载</a-button>
              <a-upload
                :action="importExcelUrl1"
                :headers="tokenHeader1"
                :multiple="false"
                :showUploadList="false"
                name="file"
                @change="handleImportExcel"
              >
                <a-button type="primary">导入</a-button>
              </a-upload>
            </div>
        </template>
        <template #manageCode='{ row,rowIndex }'>
          <a @click='handleDetail(row)'>{{ row.manageCode }}</a>
        </template>
        <template #action='{ row:record }'>
          <a @click="handleEdit(record)">编辑</a>
        </template>
        <template #status='{ row }'>
          <a-switch :checked="row.status" size="small" @change="handleStatus(row,$event)"/>
        </template>

        <template #pager>
          <vxe-pager
            :currentPage.sync='ipagination.current'
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :page-size.sync='ipagination.pageSize'
            :pageSizes='ipagination.pageSizeOptions'
            :total='ipagination.total'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->

    <repPoolModal ref='modalForm' @ok='modalFormOk'></repPoolModal>
  </a-card>
</template>

<script>
import { PageListMixin } from '@/mixins/PageListMixin'
import { getAction, postAction } from '@api/manage'
import repPoolModal from '@/views/tmr/costCenter/modules/repPoolModal'
import HpayselectCom from '@/components/cn-components/HpayselectCom'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
export default {
  name: 'repPoolManagement',
  description: '费用池管理',
  mixins: [PageListMixin],
  components: {
    repPoolModal,
    HpayselectCom
  },
  data() {
    return {
      tokenHeader1: {'loginUserToken':  Vue.ls.get(ACCESS_TOKEN)},
      loading: false,
      searchConfig: [
        {
          dictCode: 'rules_types',
          type: 'j-select',
          name: 'manageType',
          placeholder: '规则类型'
        },
        {
          dictCode: 'fee_manage_type',
          type: 'j-select',
          name: 'feeManageType',
          placeholder: '费用池类型'
        },
        {
          type: 'input',
          name: 'custCode',
          placeholder: '客户编码'
        },
        {
          type: 'input',
          name: 'custName',
          placeholder: '客户名称'
        },
        {
          type: 'a-select',
          name: 'status',
          option: [{
            name: '启用',
            value: 1
          }, {
            name: '停用',
            value: 0
          }],
          placeholder: '状态'
        },
        {
          type: 'input',
          name: 'orgCode',
          placeholder: '组织编码'
        },
        {
          type: 'input',
          name: 'orgName',
          placeholder: '组织名称'
        },
      ],
      // 表头
      columns: [
        { type: 'checkbox', width: 50, fixed: null ,field: 'a',},
        {
          title: '规则编码',
          minWidth:120,
          field: 'manageCode',
          slots: { default: 'manageCode' }
        },
        {
          title: '规则类型  ',
          minWidth:80,
          field: 'manageTypeStr',
        },
        {
          title: '费用池类型',
          minWidth:80,
          field: 'feeManageTypeStr',
        },
        {
          title: '客户编码',
          minWidth:80,
          field: 'custCode',
        },
        {
          title: '客户名称',
          minWidth:80,
          field: 'custName',
        },
        {
          title: '组织编号',
          minWidth:80,
          field: 'orgCode',
        },
        {
          title: '组织名称',
          minWidth:80,
          field: 'orgName',
        },
        {
          title: '商品层级',
          minWidth:80,
          field: 'productHierarchyName',
        },
        {
          title: '商品名称',
          minWidth:80,
          field: 'productName',
        },
        {
          title: '每单使用比例(%)',
          minWidth:120,
          field: 'usedScale'
        },
        {
          title: '备注',
          minWidth:80,
          field: 'remarks'
        },
        {
          title: '更新人',
          minWidth:80,
          field: 'updateName'
        },
        {
          title: '更新时间',
          minWidth:120,
          field: 'updateTime',
        },
        {
          title: '创建人',
          minWidth:80,
          field: 'createName'
        },
        {
          title: '创建时间',
          minWidth:120,
          field: 'createTime',
        },
        {
          title: '状态',
          minWidth:120,
          fixed: 'right',
          field: 'status',
          slots: { default: 'status' },
        },
        {
          title: '操作',
          field: 'action',
          fixed: 'right',
          minWidth:120,
          slots: { default: 'action' }
        }
      ],
      url: {
        list: window._CONFIG['domianURL'] + '/fee/cnFeeManage/findPageList',
        check:window._CONFIG['domianTpmURL'] + 'report/tpmActExecuteReport/examineReport',
        detail: window._CONFIG['domianURL'] + '/fee/cnFeeManage/getInfoByIdOrCode',
        status: window._CONFIG['domianURL'] + '/fee/cnFeeManage/startOrStop',
        startOrStopUrl: window._CONFIG['domianURL'] + '/fee/cnFeeManage/startOrStop',
        deleteBatch: window._CONFIG['domianURL'] + '/fee/cnFeeManage/deleteBatch',
        // 导入接口
        importExcelUrl: window._CONFIG['domianURL'] + "/fee/cnFeeManage/importExcel",
        // 模版下载
        exportXlsUrl: window._CONFIG['domianURL'] + "/fee/cnFeeManage/exportXls",

        closeOne: window._CONFIG['domianTpmURL'] + '/activity/closeActivity',
      }
    }
  },
  methods: {
    importExcelUrl1: function() {
      return `${this.url.importExcelUrl}`;
    },
    handleEdit: async function (record) {
      if (this.url.detail) {
        const res = await getAction(this.url.detail, {id: record.id})
        if (res && res.result) {
          record = res.result
        }else{
          this.$message.error(res.message)
        }
      }
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "编辑";
    },
    handleEdit: async function(record) {
      if (this.url.detail) {
        const res = await getAction(this.url.detail, { id: record.id })
        if (res.success) {
          record = res.result
        } else {
          this.$message.error(res.message)
        }
      }
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
    }

  },
  created() {
    this.queryParam.doc = '订货单'

  },
  // beforeMount() {
  //   const draggingMap = {};
  //   this.columns.forEach((col) => {
  //     draggingMap[col.field] = col.width;
  //   });
  //   const draggingState = Vue.observable(draggingMap);
  //   const resizeableTitle = (h, props, children) => {
  //     let thDom = null;
  //     const { key, ...restProps } = props;
  //     console.log(props)
  //     let col;
  //     // 复选框筛选处理
  //     if (key === 'selection-column') {
  //       col = {};
  //     } else {
  //       col = this.columns.find((item) => {
  //         const k = item.field || item.key;
  //         return k === key;
  //       });
  //     }
  //     // 未设置宽度或者设置不可伸缩时不做伸缩处理
  //     if (!col.width || col.noStretch) {
  //       return <th {...restProps}>{children}</th>;
  //     }
  //     const onDrag = (x) => {
  //       draggingState[key] = 0;
  //       // 设置一个伸缩的最小宽度，防止页面错乱
  //       col.width = Math.max(x, col.minWidth || 30);
  //     };
  //     const onDragstop = () => {
  //       draggingState[key] = thDom.getBoundingClientRect().width;
  //     };
  //     return (
  //       <th
  //         {...restProps}
  //         v-ant-ref={(r) => (thDom = r)}
  //         width={col.width}
  //         class="resize-table-th"
  //       >
  //         {children}
  //         <vue-draggable-resizable
  //           key={col.key}
  //           class="table-draggable-handle"
  //           w={10}
  //           x={col.width||draggingState[key]}
  //           z={1}
  //           axis="x"
  //           draggable={true}
  //           resizable={false}
  //           onDragging={onDrag}
  //           onDragstop={onDragstop}
  //         />
  //       </th>
  //     );
  //   };
  //   this.components = {
  //     header: {
  //       cell: resizeableTitle,
  //     },
  //   };
  // },
  watch: {
    // pageHeight(val){
    //   // 为了避免频繁触发resize函数导致页面卡顿，使用定时器
    //   if(!this.timer){
    //     // 一旦监听到的screenWidth值改变，就将其重新赋给data里的screenWidth
    //     this.pageHeight = val
    //     this.timer = true
    //     let that = this
    //     setTimeout(function(){
    //       // 打印screenWidth变化的值
    //       console.log(that.pageHeight)
    //       that.timer = false
    //     },100)
    //   }
    // }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  }
}
</script>

<style lang='less' scoped>
@import '~@assets/less/common.less';

/deep/ .ant-pagination {
  float: right;
}

///deep/ .resize-table-th {
//  position: relative;
//}
///deep/ .table-draggable-handle {
//  height: 100% !important;
//  bottom: 0;
//  left: auto !important;
//  right: -5px;
//  cursor: col-resize;
//  touch-action: none;
//}

</style>